
local Actor = {}
-- setmetatable(Actor, {__newindex = function(t, k, v)
--     print("[" .. k .. "]" .. "=" .. tostring(v))
--     rawset(t, k, v)
-- end})

Actor.__index = function(t, k)
    print("[" .. k .. "]")
    -- if rawget(t, k) ~= v then
    --     rawset(t, k, v)
    -- end
    return rawget(t, k)
end

Actor.__newindex = function(t, k, v)
    print("[" .. k .. "]" .. "=" .. tostring(v))
    -- if rawget(t, k) ~= v then
    --     rawset(t, k, v)
    -- end
    rawset(t, k, v)
end

---私有成员, 最好是使用table, 即唯一存在的指针, 不会重复
-- local __sig__ = "__sig__"
local __sig__ = {}

local mt = {
    __index = function(t, k)
        print("get", k)
        return t[__sig__][k]
    end,
    __newindex = function(t, k, v)
        print("set", k, v)
        t[__sig__][k] = v
    end
}

function track(t)
    local tt = {}
    tt[__sig__] = t
    setmetatable(tt, mt)
    return tt
end

local Node = track({})

local Component = {}
setmetatable(Component, Node)

return function()
    print("===>Test: lua_metatable")
    Node.a = "a"
    Node.b = "b"

    Node.a = "c"
    Node.b = "b"

    Actor.c = "c"

    Component.c = "c"
end
